package  com.zzkj.util
{
	import com.storage.vo.product.CategoryVO;
	
	import mx.collections.ArrayCollection;
	
	public class Ayc2Xmlc
	{
		private var _categoryList:ArrayCollection;
		//private var _productDic:Dictionary = new Dictionary();
		private var _parentCategory:ArrayCollection = new ArrayCollection();
		
		private var _XMLString:String;
		
		
		public function Ayc2Xmlc(ay:ArrayCollection)
		{
			_categoryList = ay;
			getPrarentCategory();
		}
		
		private function getPrarentCategory():void{
			var len:Number = _categoryList.length;
			for(var i:Number=0;i<len;i++){
				var c:CategoryVO = _categoryList[i] as CategoryVO;
				if(c.parentCategory==null){
					_parentCategory.addItem(c);
				}
			}
			createXMLString();
		}
		private function createXMLString():void{
			_XMLString = "<categorys> ";
			createChildXml(_parentCategory);
			_XMLString +="</categorys>"
			
		}
		
		private function createChildXml(pc:ArrayCollection):void{
		
			for(var i:Number =0;i<pc.length;i++){
				var c:CategoryVO = pc[i] as CategoryVO;
				_XMLString += "<category id='"+c.categoryId+"' " + 
							"name='"+c.categoryName+"' " + 
							"code='"+c.categoryCode+"'  >";
				if(c.categorys!=null && c.categorys.length>0){
					createChildXml(c.categorys);
				}
				_XMLString +="</category>"
			}
			
		}
		
		
		public function get XMLString():String{
			return this._XMLString;
		}
		public function set XMLString(value:String):void{
			this._XMLString = value;
		}

	}
}